package com.typhoon.spring_redis.utils;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class CollectionUtils {
    private static final Logger logger =LoggerFactory.getLogger(CollectionUtils.class);

    public static <T> List<T> transform(List<?> source, Class<T> clazz) {
        List list = new ArrayList(source.size());
        Iterator i$;
        try {
            for (i$ = source.iterator(); i$.hasNext(); ) {
                Object object = i$.next();
                Object t = BeanUtils.toBean(object, clazz);
                list.add(t);
            }
        } catch (Exception e) {
            logger.error("", e);
        }
        return list;
    }

    public static <T> List<T> transform(List<?> source, Class<T> clazz, String[] ignoreProperties) {
        List list = new ArrayList(source.size());
        Iterator i$;
        try {
            for (i$ = source.iterator(); i$.hasNext(); ) {
                Object object = i$.next();
                Object t = clazz.newInstance();
                BeanUtils.copyProperties(t, object, ignoreProperties);
                list.add(t);
            }
        } catch (Exception e) {
            logger.error("", e);
        }
        return list;
    }
    
    public static boolean isEmpty(List<?> list) {
    	return null == list || list.isEmpty();
    }
    
    public static boolean isNotEmpty(List<?> list) {
    	return !isEmpty(list);
    }
}
